#ifndef H_RCGD_SCC_H
#define H_RCGD_SCC_H  

//#define TOD_TX_BUF_LENGTH 32 
#define TOD_TX_BUF_LENGTH 100

#define	IsCtrlE(X) 			(X==0x05)			// Ctrl+E 가 들어왔으면.
#define	IsCtrlN(X) 			(X==0x0E)			// Ctrl+N 가 들어왔으면.
#define	IsCtrlR(X) 			(X==0x12)			// Ctrl+R 가 들어왔으면.
#define	IsCtrlT(X) 			(X==0x14)			// Ctrl+T 가 들어왔으면.


#define	IsCommandBack(X) 	(X==0x08)			// Back space가 들어왔으면.
#define	IsSlash(X) 			(X=='/')			// Slash가 들어왔으면.
#define	IsCommandChar(X) 	(X==0x20||X==0x2F||X==0x3F||(X>=0x30)&&(X<=0x39)||(X>=0x62)&&(X<=0x7A)||(X>=0x41)&&(X<=0x5A)) 

#define		BR2400				0
#define		BR4800				1
#define		BR9600				2
#define		BR19200				3
#define		BR38400				4
#define		BR57600				5
#define		BR115200			6


typedef struct BD_S{
	unsigned short	status;
	unsigned short	count;
	unsigned char	* pointer;
} BD_;


/*=================================================================*/
/*                            define                               */
/*=================================================================*/
#define 	DEBUG_PORT          2
#define 	BOTH_PORT           1
#define 	PORT_CONTROL        2
#define 	PORT_TOD            3
#define		PORT_DUAL1			4
#define		PORT_DUAL2			5
#define		PORT_COMMON			6
#define		PORT_RB				7
#define		PORT_EB				8


#define COMMAND_INDICATOR   0
#define COMMAND_STRING      1
#define COMMAND_PARAMETER   2
#define COMMAND_QUESTION    3
#define COMMAND_END         4

#define MAX_RX_BUF_NO		1


#define SCC_BUF_LENGTH	256

#define SCC1_RX_BUF_LENGTH   512

#define SCC2_RX_BUF_LENGTH   512
#define SCC3_RX_BUF_LENGTH   1024

#define SCC1_TX_BUF_LENGTH   2048
#define SCC2_TX_BUF_LENGTH   512
#define SCC3_TX_BUF_LENGTH   2048


#define SINGLE_COMMAND_LENGTH   512
#define REPLY_LENGTH    512



typedef struct UART_SCM_S{
	unsigned short TPM:2;
	unsigned short RPM:1;
	unsigned short PEN:1;
	unsigned short UM:2;
	unsigned short FRZ:1;
	unsigned short CL:1;
	unsigned short RSTM:1;
	unsigned short SL:2;
	unsigned short DIAG:2;
	unsigned short dummy:2;
	unsigned short MODE:2;
} UART_SCM_;


/* SCC UART Configuration */
typedef struct SCC_S {
		int				Baudrate;	/* 9600, 19200, ~ 115200bps*/
		UART_SCM_		MODE;
		unsigned short	SCM;
} UART_CONFIG_;




/*=================================================================*/
/*                           declaration                           */
/*=================================================================*/

extern int scc1_rx_cnt,scc2_rx_cnt,scc3_rx_cnt;



/* Direct Address Access */

extern unsigned char CommandBuffer1[SCC1_RX_BUF_LENGTH];
extern unsigned char CommandBuffer2[SCC2_RX_BUF_LENGTH];
extern unsigned char CommandBuffer3[SCC3_RX_BUF_LENGTH];


extern char BaudrateString[7][7];


extern void Init_SCC(void);
extern void SCC1_RECEIVE_HANDLING();
extern void SCC2_RECEIVE_HANDLING();
extern void SCC3_RECEIVE_HANDLING();

extern void SCC3_TRANSMIT_HANDLING();



extern void SendMessageToEB(unsigned char *, unsigned int);

extern void TransmitMessage( unsigned char *,char);
extern void TransmitnMessage(unsigned char *,int, char);

extern void SendMessageToEB_T(unsigned char *, unsigned int);


extern unsigned char tod_tx_buf[TOD_TX_BUF_LENGTH];
extern int tod_tx_ready;
extern int tod_tx_head;
extern int tod_tx_tail;



extern unsigned char control_tx_buf[SCC1_TX_BUF_LENGTH];
extern unsigned char monitor_tx_buf[SCC3_TX_BUF_LENGTH];


extern int SendEBHandler(int fd);
extern int ReceiveEBHandler(int fd); 

char *sEBCNT;
char bufMonEB[500];

typedef struct
{
	int TimeOut;
	int Head;
	int Tail;

	int RxCnt;
	int CheckOutTimeOut ;
	int Rx_TimeOut;
	int iMatch;
	int Rx_Match_TimeOut;
	unsigned char Buf[GPSRXBUFSIZE];
}GPSBUF_;


extern GPSBUF_ buf_sync15;
extern GPSBUF_ buf_f1000c;
extern GPSBUF_ buf_oemv1;
extern GPSBUF_ buf_RbSRO;
//extern GPSBUF_ buf_oemv3;

void SCC13_RECEIVE_HANDLING(char port);

#endif
